﻿using System;
using System.Collections.Generic;
using System.Text;
//
using Microsoft.Win32;

namespace DLLTest.OpertionClass
{
    class RegistryOperate
    {
        //Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键
        //Registry.CurrentUser 对应于HKEY_CURRENT_USER主键
        //Registry.LocalMachine 对应于 HKEY_LOCAL_MACHINE主键
        //Registry.User 对应于 HKEY_USER主键
        //Registry.CurrentConfig 对应于HEKY_CURRENT_CONFIG主键
        //Registry.DynDa 对应于HKEY_DYN_DATA主键
        //Registry.PerformanceData 对应于HKEY_PERFORMANCE_DATA主键
        public void isRegedit()
        {
            //创建注册表子项
            //RegistryKey current = Registry.CurrentUser;
            //RegistryKey software = current.CreateSubKey("SOFTWARE");
            //RegistryKey wxk = software.CreateSubKey("software");
            //RegistryKey wxk_INI = wxk.CreateSubKey("wxk");
            RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI");
        }

        public string isOpenReg()
        {
            string openreg=null;
            string[] subkeyName;
            RegistryKey current = Registry.CurrentUser;
            RegistryKey software = current.OpenSubKey("SOFTWARE", true);
            RegistryKey wxk = software.OpenSubKey("wxk", true);
            // RegistryKey wxk_InI=wxk.OpenSubKey("wxk.INI",true);
            subkeyName = wxk.GetSubKeyNames();//获取wxk项所有子键的名称
            foreach (string keyName in subkeyName)
            {
                if (keyName == "wxk.INI")
                {
                    //获取该子键名下的键值
                    openreg = Convert.ToString(Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\wxk\\wxk.INI", "reg", 0));
                    return openreg;

                }
                else if (keyName==null)
                {
                    return openreg;
                }
            }
            return openreg;
        }
    }
}
